//
//  CPSCHomeToolsAllTBCell.m
//  CollTest
//
//  Created by codew on 9/13/21.
//

#import "CPSCHomeToolsAllTBCell.h"
#import "CPSCWaterfallLayout.h"
#import "CPSCHomeToolsAllCollectionCell.h"
#import "CPSCHomeToolsAllCollectionCell.h"
#import "CPSCHomeToolsConstantsValue.h"
@interface CPSCHomeToolsAllTBCell ()<UICollectionViewDelegate, UICollectionViewDataSource, CPSCWaterfallLayoutDelegate>

@property (strong, nonatomic) UICollectionView * collectionView;
@property (weak, nonatomic) IBOutlet UIView *viewSuperContent;
@property (weak, nonatomic) IBOutlet UIView *viewTopSuper;
@property (weak, nonatomic) IBOutlet UILabel *lblTitle;





@property (nonatomic, assign) NSInteger indexSelect;
@property (nonatomic, strong)NSArray * dataArray;
@property (nonatomic, assign) NSInteger count;

@end

static NSString * CPSCHomeToolsAllCollectionCellIdentifier = @"CPSCHomeToolsAllCollectionCell";

@implementation CPSCHomeToolsAllTBCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    
    self.lblTitle.textColor = [UIColor colorWithHexString:@"#222222"];
    self.lblTitle.font = [UIFont systemFontOfSize:16 weight:1];
    self.lblTitle.textAlignment = NSTextAlignmentLeft;
    
    
    [self setupCollectionViewLayout];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)updateCellWithItem:(NSInteger)item
{
//    self.viewTopSuper.backgroundColor = kCPSCRandomColor;
    self.lblTitle.text = @"税务查询";
    self.count = item;
    [self.collectionView reloadData];
}

- (void)setupCollectionViewLayout
{
    // 创建布局
    CPSCWaterfallLayout *layout = [[CPSCWaterfallLayout alloc] init];
    layout.delegate = self;

    // 创建CollectionView
    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:self.viewSuperContent.bounds collectionViewLayout:layout];
    collectionView.backgroundColor = [UIColor whiteColor];
    collectionView.dataSource = self;
    collectionView.delegate = self;
    // 注册
    [collectionView registerNib:[UINib nibWithNibName:CPSCHomeToolsAllCollectionCellIdentifier bundle:nil]
      forCellWithReuseIdentifier:CPSCHomeToolsAllCollectionCellIdentifier];
    [self.viewSuperContent addSubview:collectionView];
    self.collectionView = collectionView;
    
    
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.top.right.bottom.mas_equalTo(0);
    }];
    
    [self deBugUI];
}

- (void)deBugUI
{
    
}

#pragma mark - GETTER SETTER

#pragma mark - UICollectionViewDelegate

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
}

#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{

    return self.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CPSCHomeToolsAllCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CPSCHomeToolsAllCollectionCellIdentifier
                                                                                     forIndexPath:indexPath];


    [cell updateCellWithItem:nil];
    return cell;
}

//- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
//{
//    CPSCHomeToolsAllCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CPSCHomeToolsAllCollectionCellIdentifier forIndexPath:indexPath];
//
//    if (indexPath.row == _indexSelect) {
//
////        [cell updateCellTitle:_dataArray[indexPath.row] state:VSEDBottomLabeCellStateSelected];
//    }else{
//
////        [cell updateCellTitle:_dataArray[indexPath.row] state:VSEDBottomLabeCellStateNormal];
//    }
//
//    [cell updateCellWithItem:nil];
//    return cell;
//}

#pragma mark - CPSCWaterfallLayoutDelegate
/** 每一个item的高度 */
- (CGFloat)waterflowLayout:(CPSCWaterfallLayout *)waterflowLayout
      heightForItemAtIndex:(NSUInteger)index
                 itemWidth:(CGFloat)itemWidth
{
    return CPSCHomeToolsTBCellItemViewHeight;//( ScreenWidth - 10*5 ) / 2;
}

/** 列数 */
- (CGFloat)columnCountInWaterflowLayout:(CPSCWaterfallLayout *)waterflowLayout
{
    return 2;
}

/** 每一列之间的间隙 */
- (CGFloat)columnMarginInWaterflowLayout:(CPSCWaterfallLayout *)waterflowLayout
{
    return 0;
}

/** 每一行之间的间隙 */
- (CGFloat)rowMarginInWaterflowLayout:(CPSCWaterfallLayout *)waterflowLayout
{
    return 0;
}

/** 每一个item 上下左右 的间隙 */
- (UIEdgeInsets)edgeInsetsInWaterflowLayout:(CPSCWaterfallLayout *)waterflowLayout
{
    return UIEdgeInsetsMake(0, 0, 0, 0);
}
@end
